package com.pointcircle.core.web;

import java.io.Serializable;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.pointcircle.core.JpaBaseEntity;
import com.pointcircle.core.util.PageableUtils;

public interface IFindPageRest<T extends JpaBaseEntity<ID>, ID extends Serializable, 
	EV extends EntityVo<T, ID>> 
	extends IRest<T, ID, EV> {

	@GetMapping("/findPage")
	default RestResponseList findAllByPage(
		@RequestParam(value = "page", defaultValue = "1") int page, 
		@RequestParam(value = "size", defaultValue = "10") int size) {
		Pageable pageable = PageableUtils.of(page, size);
		Page<T> entities = getRepository().findAll(pageable);
		return this.createRestResponsePageList(pageable, entities);
	}
}
